window: Allow _gtk_window_set_allocation to return a modified allocation
authorRob Bradford <rob@linux.intel.com>
Tue, 26 Feb 2013 19:33:04 +0000 (19:33 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 17 Mar 2013 15:28:26 +0000 (11:28 -0400)
Update the documentation and users of this function to handle
the future case that that we have some internal decorations to the window and
useable allocation is thus smaller.

By having a separate out parameter there is no need to have an in/out function
and allows for greater robustness.

The current implementation simply returns the allocation provided.

gtk/gtkapplicationwindow.c
gtk/gtkwindow.c
gtk/gtkwindowprivate.h

index 271054b109cfa90d98391023e10b7c70b3fabaf8..541baf6a03145dd1212d74b497692ffb749be6fc 100644 (file)
@@ -703,13 +703,17 @@ gtk_application_window_real_size_allocate (GtkWidget     *widget,
 
   if (window->priv->menubar != NULL)
     {
-      GtkAllocation menubar_allocation = *allocation;
+      GtkAllocation menubar_allocation;
+      GtkAllocation child_allocation;
       gint menubar_height;
       GtkWidget *child;
 
-      _gtk_window_set_allocation (GTK_WINDOW (widget), allocation);
+      _gtk_window_set_allocation (GTK_WINDOW (widget), allocation, &child_allocation);
+      menubar_allocation = child_allocation;
 
-      gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_height, NULL);
+      gtk_widget_get_preferred_height_for_width (window->priv->menubar,
+                                                 menubar_allocation.width,
+                                                 &menubar_height, NULL);
 
       menubar_allocation.height = menubar_height;
       gtk_widget_size_allocate (window->priv->menubar, &menubar_allocation);
@@ -717,7 +721,6 @@ gtk_application_window_real_size_allocate (GtkWidget     *widget,
       child = gtk_bin_get_child (GTK_BIN (window));
       if (child != NULL && gtk_widget_get_visible (child))
         {
-          GtkAllocation child_allocation = *allocation;
           gint border_width;
 
           border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
index 99bab056658c3ea5bcecfee84dbb48b1a11b09d6..c0dc07e97032e5ba8a42d4c4018875c7e1c42417 100644 (file)
@@ -5504,7 +5504,9 @@ set_grip_position (GtkWindow *window)
 
 /* _gtk_window_set_allocation:
  * @window: a #GtkWindow
- * @allocation: the new allocation
+ * @allocation: the original allocation for the window
+ * @allocation_out: @allocation taking decorations into
+ * consideration
  *
  * This function is like gtk_widget_set_allocation()
  * but does the necessary extra work to update
@@ -5513,13 +5515,22 @@ set_grip_position (GtkWindow *window)
  * Call this instead of gtk_widget_set_allocation()
  * when overriding ::size_allocate in a GtkWindow
  * subclass without chaining up.
+ *
+ * The @allocation parameter will be adjusted to
+ * reflect any internal decorations that the window
+ * may have. That revised allocation will then be
+ * returned in the @allocation_out parameter.
  */
 void
-_gtk_window_set_allocation (GtkWindow     *window,
-                            GtkAllocation *allocation)
+_gtk_window_set_allocation (GtkWindow           *window,
+                            const GtkAllocation *allocation,
+                            GtkAllocation       *allocation_out)
 {
   GtkWidget *widget = (GtkWidget *)window;
 
+  g_assert (allocation != NULL);
+  g_assert (allocation_out != NULL);
+
   gtk_widget_set_allocation (widget, allocation);
 
   if (gtk_widget_get_realized (widget))
@@ -5539,6 +5550,8 @@ _gtk_window_set_allocation (GtkWindow     *window,
           set_grip_position (window);
         }
     }
+
+  *allocation_out = *allocation;
 }
 
 static void
@@ -5550,16 +5563,16 @@ gtk_window_size_allocate (GtkWidget     *widget,
   GtkWidget *child;
   guint border_width;
 
-  _gtk_window_set_allocation (window, allocation);
+  _gtk_window_set_allocation (window, allocation, &child_allocation);
 
   child = gtk_bin_get_child (&(window->bin));
   if (child && gtk_widget_get_visible (child))
     {
       border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
-      child_allocation.x = border_width;
-      child_allocation.y = border_width;
-      child_allocation.width = MAX (1, allocation->width - border_width * 2);
-      child_allocation.height = MAX (1, allocation->height - border_width * 2);
+      child_allocation.x += border_width;
+      child_allocation.y += border_width;
+      child_allocation.width = MAX (1, child_allocation.width - border_width * 2);
+      child_allocation.height = MAX (1, child_allocation.height - border_width * 2);
 
       gtk_widget_size_allocate (child, &child_allocation);
     }
index 22f8d57705a76d13e04105c8a935223279855417..8891ca4c4f0a6bc1c68b0b8cfb4d75034fc4c2e5 100644 (file)
@@ -66,8 +66,9 @@ void            _gtk_window_get_wmclass            (GtkWindow  *window,
                                                     gchar     **wmclass_name,
                                                     gchar     **wmclass_class);
 
-void            _gtk_window_set_allocation         (GtkWindow     *window,
-                                                    GtkAllocation *allocation);
+void            _gtk_window_set_allocation         (GtkWindow           *window,
+                                                    const GtkAllocation *allocation,
+                                                    GtkAllocation       *allocation_out);
 
 typedef void (*GtkWindowKeysForeachFunc) (GtkWindow      *window,
                                           guint           keyval,